package cn.dengta.webapp.user.form.query;

import cn.dengta.context.model.Member;
import cn.dengta.webapp.base.form.BaseForm;
import cn.dengta.webapp.user.entity.Relation;
import cn.dengta.webapp.user.entity.User;
import lombok.*;
import me.codeplayer.util.X;

@Getter
@Setter
public class FollowQuery extends BaseForm<Relation> {

	/** 显示状态 */
	public Integer state;
	/** 状态 */
	public Integer status;
	public Integer toStatus;
	/** 用户ID */
	public Long userId;
	/** 用户ID */
	public Long toUserId;
	/** 用户昵称 */
	public String nickname;
	/** 用户昵称 */
	public String toNickname;
	/** 输出用户 0=from;1=to */
	public Integer convertUser;
	@Setter(AccessLevel.NONE)
	public User user;
	@Setter(AccessLevel.NONE)
	public User toUser;

	public void setNickname(String nickname) {
		this.nickname = nickname;
		user().setNickname(nickname);
	}

	public void setToNickname(String toNickname) {
		this.toNickname = toNickname;
		toUser().setNickname(toNickname);
	}

	public void setToAutoNickname(String toNickname) {
		Long userId = Member.decodeForInput(toNickname);
		if (userId != null) {
			setToUserId(userId);
			return;
		}
		setToNickname(toNickname);
	}

	private User user() {
		return user = X.getElse(user, User::new);
	}

	private User toUser() {
		return toUser = X.getElse(toUser, User::new);
	}

}
